/*
 * To move n discs from peg A to peg C:
 * move n−1 discs from A to B. This leaves disc #n alone on peg A
 * move disc #n from A to C
 * move n−1 discs from B to C so they sit on disc #n
 */
import java.util.Stack;
// class towerofhanoi {
	public class Tower {
		private Stack<Integer> disks; // disks
		private int index;			  // index

		//constructor	
		public Tower(int i){
			disks = new Stack<Integer>();
			this.index = i;
		}

		public int index() {
			return index;
		}
		// public void setIndex(int i){
		// 	index = i;
		// }
		public void add(int d){
			if (!disks.isEmpty() && disks.peek() <=d ){
				System.out.println("Error placing disk" + d);
			} else{
				disks.push(d);
			}
		}

		public void moveDisks(int n, Tower dest, Tower buffer) {
			if ( n > 0 ) {
				moveDisks(n-1, buffer, dest);
				moveLast(dest);
				buffer.moveDisks(n-1, dest, this);
			}
		}

		public void moveLast(Tower t){
			int top = disks.pop(); 
			t.add(top);
			System.out.println("Move disk "+top+" from " + index() +" to " + t.index());
		}
	}
	// public static void move(int n, int startPole, int endPole){
	// 	if (n== 0){
	// 			return; 
	// 		}
	// 		int intermediatePole = 6 - startPole - endPole;
	// 		move(n-1, startPole, intermediatePole);
	// 		System.out.println("Move " +n + " from " + startPole + " to " +endPole);
	// 		move(n-1, intermediatePole, endPole);		
	// }




// }	